package com.ruoyi.statisticalCenter.controller;

import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.domain.vo.InitTableVo;
import com.ruoyi.common.service.TableService;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.logistic.domain.PageInfo;
import com.ruoyi.statisticalCenter.domain.ScAssetsAndLiabilities;
import com.ruoyi.statisticalCenter.domain.vo.ScAssetsAndLiabilitiesVo;
import com.ruoyi.statisticalCenter.service.IScAssetsAndLiabilitiesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资产负债Controller
 *
 * @author ruoyi
 * @date 2024-03-16
 */
@RestController
@RequestMapping("/statisticalCenter/liabilities")
@Api(tags = "统计中心-负债报表")
public class ScAssetsAndLiabilitiesController extends BaseController {
    @Autowired
    private IScAssetsAndLiabilitiesService scAssetsAndLiabilitiesService;

    @Autowired
    private TableService tableService;

    /**
     * 查询资产负债列表
     */
    @PostMapping("/list")
    @ApiOperation("查询负债列表")
    public R list(@RequestBody ScAssetsAndLiabilitiesVo scAssetsAndLiabilities) {
        if (StringUtils.isNotBlank(scAssetsAndLiabilities.getAssetsAccount())) {
            if (scAssetsAndLiabilities.getAssetsAccount().equals("saving")) {
                scAssetsAndLiabilities.setAssetsAccount("银行存款");
            } else if (scAssetsAndLiabilities.getAssetsAccount().equals("pay")) {
                scAssetsAndLiabilities.setAssetsAccount("预付账款");
            } else {
                scAssetsAndLiabilities.setAssetsAccount("应收账款");
            }
        }
        List<ScAssetsAndLiabilities> list = scAssetsAndLiabilitiesService.selectScAssetsAndLiabilitiesList(scAssetsAndLiabilities);
        JSONObject jsonObject = new JSONObject();
        String[] fields = {
                "assetsAccount", "assetsSubaccount",
                "openingBalance", "debtor",
                "creditor", "endingBalance",
                "liabilitiesAndEquityAccounts", "liabilitiesAndEquitySubaccounts",
                "liOpeningBalance", "liDebtor",
                "liCreditor", "liEndingBalance"
        };
        InitTableVo initTableVo = new InitTableVo();
        initTableVo.setFields(fields);
        initTableVo.setCode("scAssetsAndLiabilities");
        jsonObject.put("fields", tableService.initTable(initTableVo));
        if (list != null || list.size() != 0) {
            jsonObject.put("list", PageInfo.info(list));
        }
        return R.ok(jsonObject);

    }

}
